<!DOCTYPE html>
<html>
<body>

<p>This ensures that postMessage called in a callback does not crash.

<pre>FAIL</pre>

<script src="../../../resources/run-after-layout-and-paint.js"></script>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

var n = 0;

window.onerror = function() {
    if (++n === 2) {
        document.querySelector('pre').textContent = 'PASS';
        if (window.testRunner)
            testRunner.notifyDone();
    }
    return true;
};

requestAnimationFrame(function() {
    postMessage();
    runAfterLayoutAndPaint(function() {
        setTimeout(function() {
            if (window.testRunner)
                testRunner.notifyDone();
        }, 50);
    });
});
setTimeout(postMessage);

</script>
</body>
</html>
